﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DxfNames
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string regText = comboBox1.Text.Trim();
            if (string.IsNullOrWhiteSpace(regText))
                return;
            Regex reg = new Regex(regText, RegexOptions.Compiled);
            var matchedFiles = files.Where(x => reg.IsMatch(x)).Take(30);
            listView1.Items.Clear();
            foreach (string f in matchedFiles)
            {
                ListViewItem item = new ListViewItem(f);
                Match m = reg.Match(f);
                int cnt = m.Groups.Count;
                if (cnt > 1)
                    item.SubItems.Add(m.Groups[1].Value);
                if (cnt > 2)
                    item.SubItems.Add(m.Groups[2].Value);
                if (cnt > 3)
                    item.SubItems.Add(m.Groups[3].Value);
                if (cnt > 4)
                    item.SubItems.Add(m.Groups[3].Value);
                listView1.Items.Add(item);
            }

        }
        private string[] files;
        private void Form1_Load(object sender, EventArgs e)
        {
            files = File.ReadAllLines("dxf_files_all.txt");
        }
    }
}
